<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/admin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
    <link rel="icon" href="/favicon.ico">
    <title>中环膜生产管理系统</title>
</head>
<body class="layui-layout-body" onbeforeunload="checkLeave()">
	<!-- 修改密码 -->
	<div id="formDiv" hidden>
		<form class="layui-form" id="addform">
			<br>
			<label class="layui-form-label">旧密码</label><input lay-verify="password" class="layui-input" type="password" id="password" name="password" style="width:300px;"><br>
			<label class="layui-form-label">新密码</label><input lay-verify="newPasword" class="layui-input" type="password" id="newPassword" name="newPassword" style="width:300px;"><br>
			<!-- <label class="layui-form-label">密码确认</label><input lay-verify="verifyPassword" class="layui-input" type="password" id="verifyPassword" name="verifyPassword" style="width:300px;"><br> -->
			<button class="layui-btn layui-btn-blue" lay-submit lay-filter="addform" style="margin-left:140px">修改密码</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</form>
	</div>
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header custom-header">
            
            <ul class="layui-nav layui-layout-left">
                <li class="layui-nav-item slide-sidebar" lay-unselect>
                    <a href="javascript:;" class="icon-font"><i class="ai ai-menufold"></i></a>
                </li>
            </ul>

            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">
                    <a href="javascript:;">${sessionScope.currentUser.userName}</a>
                    <dl class="layui-nav-child">
                        <dd><a href="#" id="setPassword">修改密码</a></dd>
                        <dd><a href="${pageContext.request.contextPath }/logout.do">退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <div class="layui-side custom-admin">
            <div class="layui-side-scroll">

               <div class="custom-logo">
                    <%-- <img src="${pageContext.request.contextPath }/assets/images/logo.png" alt=""/> --%>
                    <h1>中环膜生产管理系统</h1>
                </div>
                <ul id="Nav" class="layui-nav layui-nav-tree">
                    <c:forEach items="${menus }" var="menu">
                    	<li class="layui-nav-item">
                        	<a href="javascript:;">
                           		<i class="layui-icon">&#xe609;</i>
                            		<em>${menu.name }</em>
                       		</a>
                        	<dl class="layui-nav-child">
                            	<c:forEach items="${menu.children }" var="subMenu">
                            		<dd><a href="${pageContext.request.contextPath }/${subMenu.url}">${subMenu.name}</a></dd>
                            	</c:forEach>
                        	</dl>
                   		</li>
                    </c:forEach>
                </ul>

            </div>
        </div>

        <div class="layui-body">
             <div class="layui-tab app-container" lay-allowClose="true" lay-filter="tabs">
                <ul id="appTabs" class="layui-tab-title custom-tab"></ul>
                <div id="appTabPage" class="layui-tab-content"></div>
            </div>
        </div>
        <div class="mobile-mask"></div>
    </div>
    <script src="${pageContext.request.contextPath }/assets/layui.js"></script>
    <script src="${pageContext.request.contextPath }/js/public/index.js" data-main="home"></script>
    <script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
    <script type="text/javascript">
    layui.use(['table','layer','upload','form'], function(){
    	var $ = layui.jquery;
    	var form = layui.form;
    	$('#setPassword').on('click', function() {
			layer.open({
				  type: 1 		//Page层类型
				  ,area: ['25%', '40%'] //宽  高
				  ,title: '密码设置'
				  ,shade: 0.6 	//遮罩透明度
				  ,shadeClose: true //点击遮罩关闭
				  ,maxmin: true //允许全屏最小化
				  ,anim: 1 		//0-6的动画形式，-1不开启
				  ,content: $('#formDiv')
				  ,success: function () {
					  document.getElementById("addform").reset();
				  }
				  ,end: function () {
					  var formDiv = document.getElementById('formDiv');
					  formDiv.style.display = '';
					  layer.closeAll();
				  }
				});
		})
		
		/**
	     * 表单校验
	     */
	    form.verify({
	    	//value：表单的值、item：表单的DOM对象
	    	password: function(value){
	    		if(value == ''){
	    			return '不能为空';
	    		}
	    	},
	    	newPasword: function(value){
	    		if(value == ''){
	    			return '不能为空';
	    		}
	    	},
	    	/* verifyPassword: function(value){
	    		if(value == ''){
	    			return '不能为空';
	    		}
	    	} */
	    });
    	
	    /**
	     * 通用表单提交(AJAX方式)（新增）
	     */
	    form.on('submit(addform)', function (data) {
	    	$.ajax({
				url : '${pageContext.request.contextPath }/userMana/setPassword.do',
				data : $('#addform').serialize(),
				type : "get",
				dataType : "json",
				}).done(
					function(res) {
						console.log(res)
						if (res == -3) {
							console.log('ssss1')
							toastr.error('修改失败！');
							layer.closeAll();
						}
						if (res == 3) {
							console.log('ssss2')
							toastr.success('修改成功！');
							layer.close(1);
						}
						if (res == 2) {
							console.log('ssss3')
							toastr.warning('原始密码错误！');
						}
					}
				).fail(
					function(res) {
						toastr.error('修改失败！');
						layer.closeAll();
					}
				)
				return false;
	    });
    })
    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

</script>


<script type="text/javascript">

function checkLeave(){
	$.ajax({
    	type:'post',
    	url:'${pageContext.request.contextPath }/logout.do',
    	data:{},
    	success:function(data){
    	}
    }); 
} 

</script>
</body>
</html>